//
// Created by LiuDongPeng on 2023/10/27.
//

#ifndef FOC_BSP_H
#define FOC_BSP_H

#ifdef __cplusplus
extern "C" {
#endif


/* User Hardware */
#include "button.h"

#include "encoder.h"
#include "as5600.h"
#include "as5047p.h"
#include "mt6701.h"
#include "led.h"
#include "motor.h"


typedef struct foc_board
{
    uint32_t iaOffset, ibOffset, icOffset;
    float32_t shuntRs;


} foc_board_t;


/**
 * @brief On board device
 */
extern led_t bsp_blink_led, bsp_status_led;
extern button_t bsp_btn1, bsp_btn2, bsp_btn3;
extern as5600_t bsp_as5600;
extern as5047p_t bsp_as5047p;
extern mt6701_t bsp_mt6701;
extern motor_t motor1;
extern foc_board_t bsp_board;







int bsp_init();
void bsp_btn_ticks();

uint32_t bsp_get_us_tick();

void bsp_get_phase_current(foc_board_t* board, float32_t * ia, float32_t* ib, float32_t* ic);
void bsp_get_phase_current_with_sector(foc_board_t* board, int sector, float* ia, float* ib, float* ic);

void bsp_store_encoder_angle_offset(motor_t* motor);
float bsp_restore_encoder_angle_offset(motor_t* motor);



#ifdef __cplusplus
}
#endif

#endif //FOC_BSP_H
